
// shooting_game/frontend/ui.js
// UI管理和游戏状态显示

// 初始化UI元素
const scoreElement = document.getElementById('score');
const levelElement = document.getElementById('level');
const livesElement = document.getElementById('lives');
const highScoreElement = document.getElementById('highScore');
const weaponButtons = document.querySelectorAll('.weapon-btn');

// 更新游戏UI状态
function updateGameUI(score, level, lives, highScore) {
    scoreElement.textContent = score;
    levelElement.textContent = level;
    livesElement.textContent = lives;
    highScoreElement.textContent = highScore;
}

// 显示关卡提示
function showLevelUpMessage(level) {
    const message = document.createElement('div');
    message.className = 'fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-black bg-opacity-80 text-white text-2xl p-6 rounded-lg z-50';
    message.textContent = `🚀 进入第 ${level} 关!`;
    document.body.appendChild(message);
    
    setTimeout(() => {
        message.classList.add('opacity-0', 'transition-opacity', 'duration-500');
        setTimeout(() => message.remove(), 500);
    }, 1500);
}

// 武器切换效果
function updateWeaponUI(weaponType) {
    weaponButtons.forEach(btn => btn.classList.remove('active'));
    
    switch(weaponType) {
        case 'laser':
            document.getElementById('weapon1').classList.add('active');
            break;
        case 'flame':
            document.getElementById('weapon2').classList.add('active');
            break;
        case 'bomb':
            document.getElementById('weapon3').classList.add('active');
            break;
    }
}

// 显示游戏提示
function showGameTip(message, duration = 2000) {
    const tip = document.createElement('div');
    tip.className = 'fixed bottom-10 left-1/2 transform -translate-x-1/2 bg-gray-800 text-white px-4 py-2 rounded-lg text-sm';
    tip.textContent = message;
    document.body.appendChild(tip);
    
    setTimeout(() => {
        tip.classList.add('opacity-0', 'transition-opacity', 'duration-300');
        setTimeout(() => tip.remove(), 300);
    }, duration);
}

// 初始化游戏提示
document.addEventListener('DOMContentLoaded', () => {
    setTimeout(() => {
        showGameTip('使用 WASD 或方向键移动，空格键射击');
    }, 1000);
});

// 导出UI函数
export {
    updateGameUI,
    showLevelUpMessage,
    updateWeaponUI,
    showGameTip
};
